//nav
$(function() {
    $('.parentMenu').mouseover(function() {
        $(this).children(".childMenu").show();
        var left = $(this).children(".childMenu").width();
        $(this).children(".childMenu").children("li").mouseover(function () {
            $(this).children('.childMenu2').css('left',left + 'px');
            $(this).children('.childMenu2').show();
        });
    }).mouseout(function() {
        $(this).children(".childMenu").hide();
        $(this).children(".childMenu").children("li").mouseout(function () {
            $(this).children('.childMenu2').hide();
        });
    });
    $('#loginName').mouseover(function() {
        $('#loginNameSel').show();
    }).mouseout(function() {
        $('#loginNameSel').hide();
    });

    // var navList = $('.navSelect li');
    // if (location.href.indexOf('main/') !== -1) {
    //     navList[0].className = 'active';
    // } else if (location.href.indexOf('estateImportBatch/') !== -1) {
    //     navList[2].className = 'active';
    // } else if (location.href.indexOf('estate/') !== -1) {
    //     navList[1].className = 'active';
    // } else if (location.href.indexOf('analyze/') !== -1) {
    //     navList[3].className = 'active';
    // } else if (location.href.indexOf('map/') !== -1) {
    //     navList[4].className = 'active';
    // }else if (location.href.indexOf('account/') !== -1) {
    //     navList[12].className = 'active';
    // }else if ( location.href.indexOf('user/') !== -1 || location.href.indexOf('loginHistory/') !== -1) {
    //     navList[13].className = 'active';
    // }else if (location.href.indexOf('community/') !== -1) {
    //     navList[11].className = 'active';
    // }

    // 激活父菜单
    function activeParentMenu(){
        var liAList = $('.navSelect a');
        var isActive = false;
        // 方案1按照子菜单地址索引父菜单的方法来激活
        for(var i=0;i<liAList.length;i++){
            var self = $(liAList[i]);
            if(location.href == (self.prop('href'))){
                if(self.attr("parentid")){
                    var pid = self.attr("parentid");
                    self.addClass("childActive")
                    var parent = $("#"+pid).attr("parentid");
                    $("#"+pid).parent().addClass("active");
                    if(parent){
                        $("#"+parent).parent().addClass("active");
                    };
                    isActive = true;
                }
                else{
                    self.parent().addClass("active");
                    isActive = true;
                }
                break;
            }
        }
        // 如果方案1不行，就方案2：按照父节点的activeUrl判断当前url
        if(isActive == false){
            for(var i=0;i<liAList.length;i++){
                var self = $(liAList[i]);
                if(self.attr('activeUrl')!="" && location.pathname.indexOf(self.attr('activeUrl')) == 0){
                    self.parent().addClass("active");
                    isActive = true;
                    break;
                }
            }
        }
        //如果方案2也行不通,那就方案3：自己手动编写激活映射
        if(isActive == false){
            cusActiveParentMenu();
        }
    }
    // 自定义激活父菜单
    function cusActiveParentMenu(){
        var targetUrl = location.href;
        if(targetUrl.indexOf('/valueAnalyze') > -1){
            $(".navSelect a[activeUrl='/analyze']").parent().addClass("active");
        }
    }
    activeParentMenu();


    $("#changePsd").click(function () {
        var oldPsd = $(".newPsd")[0].value;
        var psd1 = $(".newPsd")[1].value;
        var psd2 = $(".newPsd")[2].value;
        if(psd1 !== psd2){
            $("#loginTS").html("俩次密码输入不一样");
            $(".newPsd")[1].value = "";
            $(".newPsd")[2].value = "";
            return;
        }else if(oldPsd.length > 18 || oldPsd.length < 6 || psd1.length > 18 || psd1.length < 6 || psd2.length > 18 || psd2.length < 6){
            $("#loginTS").html("密码长度应大于6小于18位数");
            $(".newPsd")[1].value = "";
            $(".newPsd")[2].value = "";
            return;
        }
        var data = {
            oldPassword:oldPsd,
            newPassword:psd1
        };
        $.ajax({
            type:"GET",
            url: "/user/updatePassword",
            data:data,
            success: function (mes) {
                if(mes.status == "success") {
                    $("#myModal8").modal("hide");
                    $(".newPsd")[0].value = "";
                    $(".newPsd")[1].value = "";
                    $(".newPsd")[2].value = "";
                    swal({
                        title: "修改成功!",
                        type: "success"
                    })
                }else {
                    $(".newPsd")[0].value = "";
                    $(".newPsd")[1].value = "";
                    $(".newPsd")[2].value = "";
                    $("#loginTS").html("原密码错误，请重新输入");
                }
            }
        })
    })

});